{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ab58cee4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "未成年，不允许上网\n"
     ]
    }
   ],
   "source": [
    "age =17\n",
    "money=12     #if else 嵌套 注意对应\n",
    "if age >=18:\n",
    "    print(\"已经成年，可以进入网吧\")\n",
    "    if money>=10:\n",
    "        print(\"金钱足够，可以上网\")\n",
    "    else:\n",
    "        print(\"虽然满18,但是钱不够\")\n",
    "else:\n",
    "  print(\"未成年，不允许上网\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "fdf8fe98",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "a=0\n",
    "while a<10:\n",
    "  print(a)\n",
    "  a=a+1 #与print对应  在while的后面表示 在while循环内"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "6a26223e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5050\n"
     ]
    }
   ],
   "source": [
    "i=0\n",
    "sum=0\n",
    "while i<= 100:\n",
    "  sum=sum+i\n",
    "  i +=1\n",
    "print(sum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "fe34ad57",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2550\n"
     ]
    }
   ],
   "source": [
    "i=0\n",
    "sum=0\n",
    "while i<= 100:\n",
    "  if i%2==0:#判断的话得用双等\n",
    "    sum=sum+i\n",
    "  i +=1\n",
    "print(sum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "07d7e911",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1*1=1\t\n",
      "2*1=2\t2*2=4\t\n",
      "3*1=3\t3*2=6\t3*3=9\t\n",
      "4*1=4\t4*2=8\t4*3=12\t4*4=16\t\n",
      "5*1=5\t5*2=10\t5*3=15\t5*4=20\t5*5=25\t\n",
      "6*1=6\t6*2=12\t6*3=18\t6*4=24\t6*5=30\t6*6=36\t\n",
      "7*1=7\t7*2=14\t7*3=21\t7*4=28\t7*5=35\t7*6=42\t7*7=49\t\n",
      "8*1=8\t8*2=16\t8*3=24\t8*4=32\t8*5=40\t8*6=48\t8*7=56\t8*8=64\t\n",
      "9*1=9\t9*2=18\t9*3=27\t9*4=36\t9*5=45\t9*6=54\t9*7=63\t9*8=72\t9*9=81\t\n"
     ]
    }
   ],
   "source": [
    "i=1\n",
    "while(i<10):\n",
    "    j=1#新的循环中将j重置为1\n",
    "    while(j<i+1):\n",
    "        print(f\"{i}*{j}={i*j}\",end=\"\\t\")#t为制表符\n",
    "        j=j+1\n",
    "    print()#代表换行\n",
    "    i=i+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "7111c468",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "* \n",
      "* * \n",
      "* * * \n",
      "* * * * \n",
      "* * * * * \n"
     ]
    }
   ],
   "source": [
    "i=1\n",
    "while(i<=5):\n",
    "    print(\"* \"*i)\n",
    "    i +=1\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "c510ff5f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "for i in range(10):#从0到9\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a29884ba",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1*1=1\t\n",
      "2*1=2\t2*2=4\t\n",
      "3*1=3\t3*2=6\t3*3=9\t\n",
      "4*1=4\t4*2=8\t4*3=12\t4*4=16\t\n",
      "5*1=5\t5*2=10\t5*3=15\t5*4=20\t5*5=25\t\n",
      "6*1=6\t6*2=12\t6*3=18\t6*4=24\t6*5=30\t6*6=36\t\n",
      "7*1=7\t7*2=14\t7*3=21\t7*4=28\t7*5=35\t7*6=42\t7*7=49\t\n",
      "8*1=8\t8*2=16\t8*3=24\t8*4=32\t8*5=40\t8*6=48\t8*7=56\t8*8=64\t\n",
      "9*1=9\t9*2=18\t9*3=27\t9*4=36\t9*5=45\t9*6=54\t9*7=63\t9*8=72\t9*9=81\t\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10):\n",
    "    for j in range (1,i+1):\n",
    "        print(f\"{i}*{j}={i*j}\",end=\"\\t\")#1\n",
    "    print()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pytorch",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.23"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
